package com.tdkj.service.common.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.tdkj.dao.common.IBeanFileDao;
import com.tdkj.model.common.BeanFile;
import com.tdkj.service.BaseService;
import com.tdkj.service.common.IBeanFileService;
import com.tdkj.util.FileUtil;
@Component("beanFileService")
public class BeanFileServiceImpl extends BaseService implements IBeanFileService{
	private  IBeanFileDao beanFileDao;

	public IBeanFileDao getBeanFileDao() {
		return beanFileDao;
	}

	@Resource
	public void setBeanFileDao(IBeanFileDao beanFileDao) {
		this.beanFileDao = beanFileDao;
	}

	@Override
	public void deletePhoto(Long id, String path) throws Exception {
		// TODO Auto-generated method stub
		BeanFile f=this.findById(id,BeanFile.class);
		String url=f.getUrl();
		FileUtil.deleteFile(path+"/"+url);
		beanFileDao.delete(id, BeanFile.class);
	}

	@Override
	public BeanFile findFileByUUID(String uuid) {
		// TODO Auto-generated method stub
		BeanFile f=new BeanFile();
		f.setUuid(uuid);
		List<BeanFile> l=beanFileDao.findByExample(f);
		if(l.size()>=1){
			return l.get(0);
		}else{
			return null;
		}
	}
    
}
